package com.chapter.sample.listener;

import com.chapter.sample.config.SpringConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ContextLoaderListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("ContextLoaderListener.contextInitialized");
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);

        sce.getServletContext().setAttribute("applicationContext", applicationContext);
    }
}
